<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.org/ui"
                template="../../template/tagedu.xhtml">
    <ui:define name="title">
        <title><h:outputText value="TAG - Sincronização"/></title>
    </ui:define>

    <ui:define name="content">
        <f:event type="preRenderComponent" listener="#{synchronizationBean.init()}"/>
        <h:outputText styleClass="title titletiny" value="Servidores Disponíveis"/>
        <h:form id="genSyncForm">
            <p:dataTable id="serverList" value="#{synchronizationBean.serverList}" var="server">
                <p:column>
                    <f:facet name="header">
                        <h:outputText value="Servidor" />
                    </f:facet>
                    <h:outputText value="#{synchronizationBean.findUnityName(server.serialNumber)} (#{server.serialNumber})" />
                </p:column>
                <p:column>
                    <f:facet name="header">
                        <h:outputText value="Última Atualização" />
                    </f:facet>
                    <h:outputText value="#{server.lastUpdated.time}" >
                            <f:convertDateTime pattern="dd/MM/yyyy - HH:mm"/>
                    </h:outputText>
                </p:column>
                <p:column>
                    <f:facet name="header">
                        <h:outputText value="Último Envio" />
                    </f:facet>
                     <h:outputText value="#{server.lastReceived.time}" >
                            <f:convertDateTime pattern="dd/MM/yyyy - HH:mm"/>
                    </h:outputText>
                </p:column>
                <p:column>
                    <f:facet name="header">
                        <h:outputText value="Gerar Arquivo de Retorno" />
                    </f:facet>
                    <p:commandButton  update=":genSyncForm" action="#{synchronizationBean.createSynchronizationFile()}" value="Gerar">
                        <f:setPropertyActionListener target="#{synchronizationBean.server}" value="#{server}" />
                    </p:commandButton>
                </p:column>
            </p:dataTable>
        </h:form>
        <h:form id="readSyncForm">
            <h:outputText styleClass="title titletiny" value="Arquivos Disponíveis"/>
            <p:messages id="messages" />  
            <p:dataTable value="#{synchronizationBean.filesList}" var="file">
                <p:column>
                    <f:facet name="header">
                        <h:outputText value="Arquivo" />
                    </f:facet>
                    <h:outputText value="#{file.name}" />
                </p:column>
                <p:column>
                    <f:facet name="header">
                        <h:outputText value="Status" />
                    </f:facet>
                    <h:outputText value="#{file.ok}" />
                </p:column>
                <p:column>
                    <f:facet name="header">
                        <h:outputText value="Carregar" />
                    </f:facet>
                    <p:commandButton update=":readSyncForm" action="#{synchronizationBean.readSynchronizationFile()}" value="OK">
                        <f:setPropertyActionListener target="#{synchronizationBean.file}" value="#{file}" />
                    </p:commandButton>
                </p:column>
            </p:dataTable>
        </h:form>
    </ui:define>
    <ui:define name="modals">
        <h:form>
            <p:confirmDialog message="Você tem certeza que deseja carregar este arquivo ?"
                             header="Processo de Carregamento" severity="alert"
                             widgetVar="confirmLoad">
                <p:commandButton value="Sim" actionListener="#{synchronizationBean.createSynchronizationFile}"
                                 update=":readSyncForm:messages" oncomplete="confirmation.hide()"/>
                <p:commandButton value="Ainda não" onclick="confirmation.hide();" type="button" />
            </p:confirmDialog>
        </h:form>
    </ui:define>

</ui:composition>

